package site.psvm.phoneinfo.common.util;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.query.Query;

/**
 * mongo工具类
 *
 * @author leo
 */
public class MongoUtil {

    /**
     * 获取分页排序查询
     *
     * @param page
     * @param size
     * @param isAsc 是否正序
     * @param sortFields 排序字段
     * @return Query
     */
    public static Query getPageSortQuery(int page, int size, boolean isAsc, String... sortFields) {
        Sort.Direction direction;
        if (isAsc) {
            direction = Sort.Direction.ASC;
        } else {
            direction = Sort.Direction.DESC;
        }
        return new Query().with(PageRequest.of(page, size, direction, sortFields));
    }
}
